# Maintainer: Michael Hansen <zrax0111 gmail com>

_realname=unicorn
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-unicorn")
pkgver=1.0.1
pkgrel=1
pkgdesc='A lightweight multi-platform, multi-architecture CPU emulator framework based on QEMU'
url='http://www.unicorn-engine.org/index.html'
arch=('any')
license=('GPL2')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/unicorn-engine/unicorn/archive/${pkgver}.tar.gz")
sha512sums=('edfe1f7bfbc1d20f5b62232057e194a937bc09db686ef2efadb33a54605029a53426432cdb2a29511385aacdb9343b3b3091af50a1909098d7cf6db3429eb966')

prepare() {
  cd "${_realname}-${pkgver}"
  sed 's|-O3|-O2|g' -i Makefile qemu/configure
  sed 's|-g ||g' -i qemu/configure
  sed 's|UNICORN_DEBUG ?= yes|UNICORN_DEBUG ?= no|g' -i config.mk
}

build() {
  cd "${_realname}-${pkgver}"
  make clean
  make PREFIX="${MINGW_PREFIX}"
}

package() {
  cd "${_realname}-${pkgver}"

  make DESTDIR="${pkgdir}" PREFIX="${MINGW_PREFIX}" install
  install -dm755 "${pkgdir}/${MINGW_PREFIX}/bin"
  mv "${pkgdir}/${MINGW_PREFIX}/lib/unicorn.dll" "${pkgdir}/${MINGW_PREFIX}/bin/libunicorn.dll"
  mv "${pkgdir}/${MINGW_PREFIX}/lib/unicorn.a" "${pkgdir}/${MINGW_PREFIX}/lib/libunicorn.a"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}/${MINGW_PREFIX}/share/licenses/${pkgname}/COPYING"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING_GLIB" "${pkgdir}/${MINGW_PREFIX}/share/licenses/${pkgname}/COPYING_GLIB"
}
